This section contains tips on functional programming and ZERO theory. :).
!!! So enjoy !!!
In [2]:
# Original
x = 20
if(x > 1):
print("True:", x)
# eleminating if
x = 20
a = (x > 1 and ("True: " + str(x)))
print(a)
In [4]:
# Eleminating if else
x = 10
if (x > 1):
print("True:", x)
else:
print("False:", x)
In [8]:
x = -20
a = (x > 1 and ("True:", str(x))) or ("False:", str(x))
print(a)
print(" ".join(a))
In [9]:
x = 20
a = (x > 1 and ("true " + str(x))) or ("false " + str(x))
print(a)
In [10]:
x = -20
a = (x > 1 and ("true " + str(x))) or ("false " + str(x))
print(a)
In [14]:
x = -20
a = x > 1 and x or x*x
print(a)
In [ ]:
AND
0 0 0
0 1 0
1 0 0
1 1 1
or
0 0 0
0 1 1
1 0 1
1 1 1
In [20]:
x = 0
if (x == 0):
print("False")
elif (x == 1):
print("True")
else:
print("Not boolean")
print("*"*11)
a = (x == 0 and "False") or ((x == 1 and "True") or "Not Boolean")
print(a)
In [18]:
# Eleminating if elif else
x = 1
if (x == 0):
print("False")
elif (x == 1):
print("True")
else:
print("Not boolean")
print("*"*11)
a = (x == 0 and "False") or ((x == 1 and "True") or "Not Boolean")
print(a)
In [21]:
x = 12
if (x == 0):
print("False")
elif (x == 1):
print("True")
else:
print("Not boolean")
print("*"*11)
a = (x == 0 and "False") or ((x == 1 and "True") or "Not Boolean")
print(a)
In [12]:
# Eliminating Sequential Statement
def double(x):
return(x+x)
d = []
for x in range(20):
d.append(double(x))
print(d)
# Using import map
print("*"*75)
d = list(map(double, range(20)))
print(d)
In [22]:
# Eliminating While Statement
def double(x):
return(x+x)
x = 1
d = []
while x < 20:
d.append(double(x))
x = x + 1
print(d)
### !!! TODO !!!
## while_FP = lambda: (<cond> and while_block()) or while_FP()